package org.teachertools.services;

import javax.persistence.Query;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;
import org.teachertools.data.Livret;

@Repository
public class LivretService extends GenericService<Livret> {

    @Override
    protected Class<Livret> getObjectClass() {
        return Livret.class;
    }

    @Override
    protected Query getSearchQuery(Livret livret) {
        StringBuffer request = new StringBuffer();
        request.append("from Livret entity left join fetch entity.competences where 1 = 1");
        if (StringUtils.isNotEmpty(livret.getNom())) {
            request.append(" and upper(entity.nom) like upper(:label_1)");
        }
        Query query = entityManager.createQuery(request.toString());
        if (StringUtils.isNotEmpty(livret.getNom())) {
            query.setParameter("label_1", prepareQueryParam(livret.getNom()));
        }
        return query;
    }
}
